package com.mew.common.rest.user;

import com.mew.common.entity.config.LevelVip;
import com.mew.common.rest.MewResponse;
import com.zebra.common.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.ToString;

import java.util.List;

@Data
@ToString
public class VipInfoMessage extends MewResponse<VipInfoMessage> {

    public int vip;
    public long exp;
    public double rate;

    public List<Level> levels;


    @Override
    public void write(ByteBuf b){

        writeInt(b,vip);
        writeLong(b,exp);
        writeInt(b, (int) (rate*1000));
        writeInt(b,levels.size());
        for (Level level : levels) {
            level.write(b);
        }
    }

    @Override
    public VipInfoMessage read(ByteBuf byteBuf) {
        return null;
    }

    @Data
    @ToString
    public static class Level{
        int vip;
        long exp;
        int onlineCoeff;
        int friendGoldCoeff;
        long loginGold;
        long levelUpGold;

        public void toLeve(LevelVip levelVip){
            this.vip = levelVip.getId();
            this.exp = levelVip.getExp();
            this.onlineCoeff = levelVip.getOnlineCoeff();
            this.friendGoldCoeff = levelVip.getFriendGoldCoeff();
            this.loginGold = levelVip.getLoginGold();
            this.levelUpGold = levelVip.getLevelUpGold();
        }

        public void write(ByteBuf b){
            ByteBufUtils.writeInt(b,vip);
            ByteBufUtils.writeLong(b,exp);
            ByteBufUtils.writeInt(b,onlineCoeff);
            ByteBufUtils.writeInt(b, friendGoldCoeff);
            ByteBufUtils.writeLong(b,loginGold);
            ByteBufUtils.writeLong(b,levelUpGold);
        }
    }
}
